package com.ruoyi.web.controller.system;

import com.ruoyi.cart.domain.Cart;
import com.ruoyi.cart.service.ICartService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.orders.domain.Orders;
import com.ruoyi.orders.service.IOrdersService;
import com.ruoyi.reviews.domain.ProductCommentDTO;
import com.ruoyi.reviews.domain.UserReviews;
import com.ruoyi.reviews.service.IProductCommentDTOService;
import com.ruoyi.reviews.service.IUserReviewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app/order")
public class AppOrderController extends BaseController {
    @Autowired
    private ICartService cartService;
    @Autowired
    private IOrdersService ordersService;
    @Autowired
    private IUserReviewsService userReviewsService;
    @Autowired
    private IProductCommentDTOService productCommentService;
    /**
     * 新增购物车
     */
    @PostMapping("/addItem")
    public AjaxResult add(@RequestBody Cart cart)
    {
        return toAjax(cartService.insertCart(cart));
    }
    /**
     * 查询购物车列表
     */
    @GetMapping("/getItemList")
    public AjaxResult list(Cart cart)
    {
        startPage();
        List<Cart> list = cartService.selectCartList(cart);
        return AjaxResult.success(list);
    }
    /**
     * 删除购物车条目
     */
    @DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(cartService.deleteCartByItemIds(itemIds));
    }
    /**
     * 修改购物车
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Cart cart)
    {
        return toAjax(cartService.updateCart(cart));
    }
    /**
     * 新增订单
     */
    @PostMapping("/addOrder")
    public AjaxResult add(@RequestBody Orders orders)
    {
        return toAjax(ordersService.insertOrders(orders));
    }
    /**
     * 查询订单列表
     */
    @GetMapping("/getOrderList")
    public AjaxResult list(Orders orders)
    {
        List<Orders> list = ordersService.selectOrdersList(orders);
        return AjaxResult.success(getDataTable(list));
    }
    /**
     * 新增用户评价
     */

    @PostMapping("/addComment")
    public AjaxResult add(@RequestBody UserReviews userReviews)
    {
        return toAjax(userReviewsService.insertUserReviews(userReviews));
    }

    @GetMapping("/getComment")
    public AjaxResult list(@RequestParam String productId){
        System.out.println("66"+ productId);
        List<ProductCommentDTO> list = productCommentService.getProductComment(productId);
        System.out.println("我在找："+list);
        return AjaxResult.success(list);

    }
}
